export class Storage {
	storage: typeof localStorage | typeof sessionStorage
	constructor(storage: typeof localStorage | typeof sessionStorage) {
		this.storage = storage
	}
	getItem<T = string>(key: string): T {
		try {
			return JSON.parse(this.storage.getItem(key) as string)
		} catch {
			return this.storage.getItem(key) as T
		}
	}
	setItem(key: string, value: any) {
		if (typeof value === 'object' || typeof value === 'function') {
			this.storage.setItem(key, JSON.stringify(value))
		} else {
			this.storage.setItem(key, (value))
		}
	}
	removeItem(key: string) {
		this.storage.removeItem(key)
	}
	clear() {
		this.storage.clear()
	}
}


export const l = new Storage(localStorage)
export const s = new Storage(sessionStorage)



